package com.sqrj.phoneorder.util;

//import com.sqrj.phoneorder.util.strategy.DefaultWorkerIdStrategy;

import com.sqrj.phoneorder.util.strategy.DefaultWorkerIdStrategy;

/**
 * Created by xxlc on 2018/5/25.
 */
public class Id {
    private static WorkerIdStrategy workerIdStrategy;
    private static IdWorker idWorker;



    public static synchronized void configure(WorkerIdStrategy custom) {
        if (workerIdStrategy == custom) return;

        if (workerIdStrategy != null) workerIdStrategy.release();
        workerIdStrategy = custom;
        workerIdStrategy.initialize();
        idWorker = new IdWorker(workerIdStrategy.availableWorkerId());
    }

    public static long next() {
        return idWorker.nextId();
    }

    public static long getWorkerId() {
        return idWorker.getWorkerId();
    }
}
